package com.poptap.base.domain;

import java.io.Serializable;
import java.util.Date;

import org.bson.types.ObjectId;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.springframework.data.annotation.Id;

import com.poptap.base.json.ObjectIdSerializer;
import com.poptap.bean.ArgumentEntity;

public abstract class BaseEntity implements ArgumentEntity, Serializable {

	private static final long serialVersionUID = 5756138036288673254L;

	@Id
	private ObjectId id;
	
	private Date createTime;
	
	@JsonSerialize(using=ObjectIdSerializer.class)
	public ObjectId getId() {
		return id;
	}
	
	public void setId(ObjectId id) {
		this.id = id;
	}
	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof BaseEntity) {
			BaseEntity entity = (BaseEntity) obj;
			return null != obj && id.equals(entity.getId());
		}
		return false;
	}
	
	@Override
	public String toString() {
		return id.toString();
	}

}
